package dbAccess;

import java.io.*;
import java.sql.*;
import java.lang.*;

public class Login {

	private String EmailAddress;
	private String SIN;
	private String firstName;
	private String lastName;
	private String phoneNum;
	private String homeAddress;
	private String password;
	private String gender;
	private java.sql.Date DateOfBirth;
		
	public int UserLogin(String userId, String password, String type)
	{
		DbAccess access = new DbAccess();
		Connection conn;
		ResultSet rs;
		String query;
		String returnedPassword;
		String tableName;
		
		conn = access.connect();
		if (conn == null)
		{
			return -1;
		}
		
		if (type.equals("Doctor"))
		{
			tableName = "tbl_doctor";
			
		}
		else if (type.equals("Patient"))
		{
			tableName = "tbl_patient";
		}
		else if (type.equals("Staff"))
		{
			tableName = "tbl_staff";
		}
		else if (type.equals("Financial Officer"))
		{
			tableName = "tbl_finance";
		}
		else if (type.equals("Admin"))
		{
			tableName = "tbl_admin";
		}
		else
		{
			tableName = "";
			return -1;
		}
	
		query = "select Password from " + tableName + " where ";
		query += "IsDeleted = 0 and EmailAddress = '" + userId + "'";
		returnedPassword = access.ExecuteScalar(access.connect(), query);

		if(!password.equals(returnedPassword))
		{
			//incorrect password or invalid user id
			access.CloseConnection(conn);
			return 0;
		}
		else if(password.equals(returnedPassword))
		{
			//valid login so populate private fields and navigate to appropriate page
			query = "select * from " + tableName + " where ";
			query += "IsDeleted = 0 and EmailAddress = '" + userId + "' ";
			rs = access.ExecuteSelect(access.connect(), query);
			
			try
			{
				while (rs.next())
				{
					this.setSIN(rs.getString("SIN"));
					this.setFirstName(rs.getString("FirstName"));
					this.setLastName(rs.getString("LastName"));
					this.setPhoneNum(rs.getString("Phone"));
					this.setEmailAddress(rs.getString("EmailAddress"));
					this.setHomeAddress(rs.getString("HomeAddress"));
					this.setDateOfBirth(rs.getDate("DateOfBirth"));
					this.setGender(rs.getString("Gender"));
					this.setPassword(rs.getString("Password"));
				}
			}
			catch (SQLException e)
			{
				return -1;
			}
			
			access.CloseConnection(conn);
			return 1; //success
		}
		else
		{
			//something weird just happened
			access.CloseConnection(access.connect());
			return -1;
		}
		
	}
	
	//doctor personal information on doctor home page
	public ResultSet getDocInfo(int SIN)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		
		if(conn == null)
		{
			return (ResultSet)null;
		}
		else
		{
			String query = "select tbl_doctor.DocId, tbl_doctor.FirstName as DocFirstName, ";
			query += "tbl_doctor.LastName as DocLastName, tbl_doctor.Phone, tbl_doctor.HomeAddress, ";
			query += "tbl_doctor.Gender, tbl_doctor.DateOfBirth, tbl_doctor.DocBuilding, tbl_doctor.DocRoom, ";
			
			query += "tbl_doctor.SIN ";
			query += "from tbl_doctor where tbl_doctor.SIN = " + SIN + " and tbl_doctor.IsDeleted = 0";
			
			rs = access.ExecuteSelect(conn, query);
		}
		return rs;
			
	}
	
	//financial officer personal information on finance home page
	public ResultSet getFinanceInfo(int SIN)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		
		if(conn == null)
		{
			return (ResultSet)null;
		}
		else
		{
			String query = "select tbl_finance.FinanceId, tbl_finance.FirstName as FinanceFirstName, ";
			query += "tbl_finance.LastName as FinanceLastName, tbl_finance.Phone, tbl_finance.HomeAddress, ";
			query += "tbl_finance.Gender, tbl_finance.DateOfBirth, tbl_finance.SIN ";
			query += "from tbl_finance where tbl_finance.SIN = " + SIN + " and tbl_finance.IsDeleted = 0";
			
			rs = access.ExecuteSelect(conn, query);
		}
		return rs;
			
	}
	
	//patient personal information on patient home page
	public ResultSet getPatientInfo(int SIN)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		if (conn == null)
		{
			return (ResultSet)null;
		}
		else 
		{
			String query = "select tbl_patient.PatientId, tbl_patient.FirstName as PatientFirstName, ";
			query += "tbl_patient.LastName as PatientLastName, tbl_patient.Phone, tbl_patient.EmailAddress, tbl_patient.HomeAddress, ";
			query += "tbl_patient.Gender, tbl_patient.DateOfBirth, tbl_patient.HealthCard, tbl_patient.CurrentHealth, ";
			query += "tbl_patient.DocId, tbl_doctor.FirstName as DocFirstName, ";
			query += "tbl_doctor.LastName as DocLastName from tbl_patient inner join tbl_doctor ";
			query += "on tbl_patient.DocId = tbl_doctor.DocId ";
			query += "where tbl_patient.SIN = " + SIN + " and tbl_patient.IsDeleted = 0";
			
			rs = access.ExecuteSelect(conn, query);
		}
		return rs;
	}
	
	//patient2appt - sees all past and future appointments
	public ResultSet getAllPatientAppointments(int patientId)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		if (conn == null)
		{
			return (ResultSet)null;
		}
		else 
		{
			String query = "select tbl_appointment.AppointmentId, tbl_appointment.Date, tbl_appointment.StartTime, tbl_appointment.EndTime, ";
			query += "tbl_appointment.Building, tbl_appointment.Room, ";
			query += "tbl_doctor.FirstName as DocFirstName, tbl_doctor.LastName as DocLastName, tbl_visit.visitId ";
			query += "from tbl_appointment inner join tbl_doctor ";
			query += "on tbl_appointment.DocId = tbl_doctor.DocId ";
			query += "left join tbl_visit on (tbl_appointment.AppointmentId = tbl_visit.AppointmentId) ";
			query += "where tbl_appointment.PatientId = '" + patientId + "' and tbl_appointment.IsDeleted = '0' ";
			query += "order by tbl_appointment.Date desc";
			rs = access.ExecuteSelect(conn, query);
		}
		return rs;
	}
	
	//staff personal information on staff home page
	public ResultSet getStaffInfo(int SIN)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		if (conn == null)
		{
			return (ResultSet)null;
		}
		else 
		{
			String query = "select tbl_staff.StaffId, tbl_staff.DocId, ";
			query += "tbl_staff.Phone, tbl_staff.HomeAddress,tbl_staff.Gender,tbl_staff.DateOfBirth, ";
			query += "tbl_staff.DocId, tbl_doctor.FirstName as DocFirstName, ";
			query += "tbl_doctor.LastName as DocLastName ";
			query += "from tbl_staff inner join tbl_doctor on  tbl_staff.DocId = tbl_doctor.DocId ";
			query += "where tbl_staff.SIN = " + SIN + " and tbl_staff.IsDeleted = 0 ";
			
			rs = access.ExecuteSelect(conn, query);
		}
		return rs;
	}
	
	public ResultSet getVisitSearchResults(String fieldName1, String value1, 
			String fieldName2, String value2, String fieldName3, String value3)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		String query;
		String tableName = "tbl_visit";
		
		if(("").equals(value1) && ("").equals(value2) && ("").equals(value3))
		{
			return (ResultSet) null;
		}
		conn = access.connect();
		if(conn == null)
		{
			return (ResultSet)null;
		}
		
		query = "select * from " + tableName + " where ";
		
		if (!(("").equals(value1)))
		{
			query += tableName + "." + fieldName1 + " like '%" + value1 + "%' "; 
			if (!(("").equals(value2)))
			{
				query += "and " + tableName + "." + fieldName2 + " like '%" + value2 + "%' ";
				if (!(("").equals(value3)))
				{
					query += "and " + tableName + "." + fieldName3 + " like '%" + value3 + "%' ";
				}
			}
			else
			{
				if (!(("").equals(value3)))
				{
					query += "and " + tableName + "." + fieldName3 + " like '%" + value3 + "%' ";
				}	
			}		
		}
		else
		{
			if (!(("").equals(value2)))
			{
				query += tableName + "." + fieldName2 + " like '%" + value2 + "%' ";
				if (!(("").equals(value3)))
				{
					query += "and " + tableName + "." + fieldName3 + " like '%" + value3 + "%' ";
				}
			}
			else //value 3 can't be empty
			{
				query += tableName + "." + fieldName3 + " like '%" + value3 + "%' ";
			}
		}
		query += "and " + tableName + ".IsDeleted = '0'";
		rs = access.ExecuteSelect(access.connect(), query);	
		return rs;
	}
	
	// get person search results for staff, doctor
	public ResultSet getPersonSearchResults(String typeOfPerson, String fieldName1, 
			String value1, String fieldName2, String value2, String fieldName3, String value3)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		String query;
		String tableName;
		
		if(("").equals(value1) && ("").equals(value2) && ("").equals(value3))
		{
			return (ResultSet) null;
		}
		conn = access.connect();
		if(conn == null)
		{
			return (ResultSet)null;
		}
		tableName = "tbl_" + typeOfPerson;
		query = "select * from " + tableName + " where ";
		
		if (!(("").equals(value1)))
		{
			query += tableName + "." + fieldName1 + " = '" + value1 + "' "; 
			if (!(("").equals(value2)))
			{
				query += "and " + tableName + "." + fieldName2 + " = '" + value2 + "' ";
				if (!(("").equals(value3)))
				{
					query += "and " + tableName + "." + fieldName3 + " = '" + value3 + "' ";
				}
			}
			else
			{
				if (!(("").equals(value3)))
				{
					query += "and " + tableName + "." + fieldName3 + " = '" + value3 + "' ";
				}	
			}		
		}
		else
		{
			if (!(("").equals(value2)))
			{
				query += tableName + "." + fieldName2 + " = '" + value2 + "' ";
				if (!(("").equals(value3)))
				{
					query += "and " + tableName + "." + fieldName3 + " = '" + value3 + "' ";
				}
			}
			else //value 3 can't be empty
			{
				query += tableName + "." + fieldName3 + " = '" + value3 + "' ";
			}
		}
		query += "and " + tableName + ".IsDeleted = '0'";
		rs = access.ExecuteSelect(access.connect(), query);	
		return rs;
	}
	
	//get patient list for staff, doctor
	public ResultSet getPatientList(int personId, String type)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		if (conn == null)
		{
			return (ResultSet)null;
		}
		else
		{
			String query;
			
			if (type.equals("Doctor")) //doctor
			{
				query = "select tbl_patient.PatientId,tbl_patient.FirstName, tbl_patient.LastName, ";
				query += "tbl_patient.Gender,tbl_patient.DateOfBirth, tbl_patient.Phone, tbl_patient.EmailAddress, tbl_patient.HealthCard, ";
				query += "tbl_patient.CurrentHealth from tbl_patient where (tbl_patient.DocId = " + personId + " or ";
				query += "tbl_patient.PatientId in ";
				query += "(select tbl_doc_patient_access.PatientId from tbl_doc_patient_access where ";
				query += "tbl_doc_patient_access.DocId = " + personId + ")) and ";
				query += "tbl_patient.IsDeleted = 0";
			}
			else if (type.equals("Staff")) //staff
			{
				query = "select tbl_patient.PatientId, tbl_patient.FirstName, tbl_patient.LastName, ";
				query += "tbl_patient.Gender, tbl_patient.DateOfBirth, tbl_patient.Phone, "; 
				query += "tbl_patient.EmailAddress, tbl_patient.HealthCard, tbl_patient.CurrentHealth ";
				query += "from tbl_patient inner join tbl_staff on tbl_patient.DocId = tbl_staff.DocId ";
				query += "where tbl_staff.StaffId = " + personId + " and tbl_patient.IsDeleted = 0 ";
			}
			else
			{
				return (ResultSet)null;
			}
			rs = access.ExecuteSelect(conn, query);				
		}
		return rs;
	}
	
	// doctor list - financial officer
	public ResultSet getDoctorList(String type)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		if (conn == null)
		{
			return (ResultSet)null;
		}
		else
		{
			String query;
			
			if (type.equals("Financial Officer")) //financial officer
			{
				query = "select tbl_doctor.DocId,tbl_doctor.FirstName, tbl_doctor.LastName, ";
				query += "tbl_doctor.Gender,tbl_doctor.DateOfBirth, tbl_doctor.Phone, tbl_doctor.EmailAddress, tbl_doctor.DocRoom, ";
				query += " tbl_doctor.DocBuilding, tbl_doctor.HomeAddress, tbl_doctor.Password from tbl_doctor where tbl_doctor.IsDeleted = 0";
				
			}
			else if (type.equals("Admin")) //Admin
			{
				query = "select tbl_doctor.DocId,tbl_doctor.FirstName, tbl_doctor.LastName, ";
				query += "tbl_doctor.Gender,tbl_doctor.DateOfBirth, tbl_doctor.Phone, tbl_doctor.EmailAddress, tbl_doctor.DocRoom, ";
				query += " tbl_doctor.DocBuilding, tbl_doctor.HomeAddress, tbl_doctor.Password from tbl_doctor where tbl_doctor.IsDeleted = 0";
				
			}
			else
			{
				return (ResultSet)null;
			}
			rs = access.ExecuteSelect(conn, query);				
		}
		return rs;
	}
	
	public ResultSet getPatientListForAdmin(String type)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		if (conn == null)
		{
			return (ResultSet)null;
		}
		else
		{
			String query;
			
			if (type.equals("Admin")) //Admin
			{
				query = "select tbl_patient.PatientId,tbl_patient.FirstName, tbl_patient.CurrentHealth, tbl_patient.HealthCard, tbl_patient.LastName, ";
				query += "tbl_patient.Gender, tbl_patient.HomeAddress, tbl_patient.Password, tbl_patient.DocId, tbl_patient.DateOfBirth, tbl_patient.Phone, tbl_patient.EmailAddress";
				query += " from tbl_patient where tbl_patient.IsDeleted = 0";
				
			}
			else
			{
				return (ResultSet)null;
			}
			rs = access.ExecuteSelect(conn, query);				
		}
		return rs;
	}
	
	public ResultSet getStaffListForAdmin(String type)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		if (conn == null)
		{
			return (ResultSet)null;
		}
		else
		{
			String query;
			
			if (type.equals("Admin")) //Admin
			{
				query = "select tbl_staff.StaffId,tbl_staff.FirstName, tbl_staff.LastName, ";
				query += "tbl_staff.Gender, tbl_staff.HomeAddress, tbl_staff.Password, tbl_staff.DateOfBirth, tbl_staff.Phone, tbl_staff.EmailAddress";
				query += " from tbl_staff where tbl_staff.IsDeleted = 0";
				
			}
			else
			{
				return (ResultSet)null;
			}
			rs = access.ExecuteSelect(conn, query);				
		}
		return rs;
	}
	
	public ResultSet getAdminListForAdmin(String type)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		if (conn == null)
		{
			return (ResultSet)null;
		}
		else
		{
			String query;
			
			if (type.equals("Admin")) //Admin
			{
				query = "select tbl_admin.HomeAddress, tbl_admin.AdminId,tbl_admin.FirstName, tbl_admin.LastName, ";
				query += "tbl_admin.Gender,tbl_admin.DateOfBirth, tbl_admin.Phone, tbl_admin.EmailAddress, tbl_admin.Password";
				query += " from tbl_admin where tbl_admin.IsDeleted = 0";
				
			}
			else
			{
				return (ResultSet)null;
			}
			rs = access.ExecuteSelect(conn, query);				
		}
		return rs;
	}
	
	public ResultSet getFinanceListForAdmin(String type)
	{
		ResultSet rs;
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		if (conn == null)
		{
			return (ResultSet)null;
		}
		else
		{
			String query;
			
			if (type.equals("Admin")) //Admin
			{
				query = "select tbl_finance.FinanceId,tbl_finance.FirstName, tbl_finance.LastName, ";
				query += "tbl_finance.Gender,tbl_finance.DateOfBirth, tbl_finance.Phone, tbl_finance.HomeAddress, tbl_finance.Password, ";
				query += "tbl_finance.EmailAddress from tbl_finance where tbl_finance.IsDeleted = 0";
				
			}
			else
			{
				return (ResultSet)null;
			}
			rs = access.ExecuteSelect(conn, query);				
		}
		return rs;
	}
	
	
	//get appointments for doctor/staff
	public ResultSet getAppointmentList(int personId, String type, java.util.Date startDate, java.util.Date endDate)
	{
		ResultSet rs;
		
		DbAccess access = new DbAccess();
		Connection conn;
		conn = access.connect();
		if (conn == null)
		{
			return (ResultSet)null;
		}
		else
		{
			String query;
			query = "select tbl_appointment.AppointmentId, ";
			query += "tbl_patient.FirstName as patientFirstName, tbl_patient.LastName as patientLastName, tbl_patient.PatientId, ";
			query += "tbl_appointment.Date, tbl_appointment.StartTime, tbl_appointment.EndTime, ";
			query += "tbl_appointment.Building, tbl_appointment.Room, tbl_visit.VisitId ";
			query += "from (tbl_appointment inner join tbl_patient ";
			query += "on tbl_appointment.PatientId = tbl_patient.PatientId) ";
			query += "left join tbl_visit on (tbl_appointment.AppointmentId = tbl_visit.AppointmentId) ";
			query += "where tbl_appointment.Date >= '" + startDate + "' ";
			query += "and tbl_appointment.Date <= '" + endDate+ "' ";
			query += "and tbl_appointment.IsDeleted = 0 ";
			query += "and (tbl_visit.IsDeleted is null or tbl_visit.IsDeleted = 0) ";
			
			if (type.equals("Doctor")) //doctor
			{
				query += "and tbl_appointment.DocId = '" + personId + "' ";
				query += "order by tbl_appointment.Date";

			}
			else if (type.equals("Patient")) //patient
			{
				query += "and tbl_appointment.PatientId = '" + personId + "' ";
				query += "order by tbl_appointment.Date";
			}
			else if (type.equals("Staff")) //staff
			{
				query += "and tbl_appointment.StaffId = '" + personId + "' ";
				query += "order by tbl_appointment.Date, tbl_appointment.StartTime";
			}
			else if (type.equals("Financial Officer")) //financial officer
			{
				query += "and tbl_appointment.DocId = '" + personId + "' ";
				query += "order by tbl_appointment.Date, tbl_appointment.StartTime";
			}
			else
			{
				return (ResultSet)null;
			}
			rs = access.ExecuteSelect(conn, query);
		}
		return rs;
	}
	
	public ResultSet getVisitList(int personId, String type, String patientId)
	{
		ResultSet rs;
		
		DbAccess access = new DbAccess();
		Connection conn;
		String query;
		conn = access.connect();
		if (conn == null)
		{
			return (ResultSet)null;
		}
		else
		{
			if (type.equals("Doctor")) //doctor
			{
				query = "select * from tbl_visit inner join tbl_appointment on ";
				query += "(tbl_visit.AppointmentId = tbl_appointment.AppointmentId) ";
				query += "inner join tbl_patient on tbl_appointment.PatientId = tbl_patient.PatientId ";
				query += "where tbl_visit.IsDeleted = 0 and tbl_appointment.PatientId = " + patientId + " and ";
				query += "(tbl_patient.DocId = " + personId + " or exists ";
				//check for access rights
				query += "(select * from tbl_doc_patient_access ";
				query += "where tbl_doc_patient_access.DocId = " + personId + " and ";
				query += "tbl_doc_patient_access.PatientId = " + patientId + " and ";
				query += "tbl_doc_patient_access.Valid = 1))";
			}
			else if (type.equals("Patient")) //patient
			{
				//must check access rights:
				query = "select tbl_visit.AppointmentId, tbl_visit.Diagnosis, ";
				query += "tbl_visit.Prescription, tbl_visit.Dosage ";
				query += "from tbl_visit inner join tbl_appointment ";
				query += "on tbl_visit.AppointmentId = tbl_appointment.AppointmentId ";
				query += "where tbl_appointment.PatientId = " + patientId + " and tbl_visit.IsDeleted = 0";
			}
			else if (type.equals("Staff")) //staff
			{
				query = "select * from tbl_visit inner join tbl_appointment on ";
				query += "(tbl_visit.AppointmentId = tbl_appointment.AppointmentId) ";
				query += "where tbl_appointment.PatientId = " + patientId + " and tbl_visit.IsDeleted = 0 ";
				query += "and exists ";
				//check for access rights
				query += "(select * from tbl_staff_patient_access ";
				query += "where tbl_staff_patient_access.staffId = " + personId + " ";
				query += "and tbl_staff_patient_access.PatientId = " + patientId + " ";
				query += "and tbl_staff_patient_access.Valid = 1)";
			}
			else
			{
				return (ResultSet)null;
			}
			rs = access.ExecuteSelect(conn, query);
		}
		return rs;
	}
	
	public ResultSet getVisitDetails(String type, int visitId)
	{
		DbAccess access = new DbAccess();
		ResultSet rs;
		String query;
		
		if (type.equals("Doctor"))
		{
			query = "select tbl_visit.*, tbl_appointment.PatientId,tbl_patient.FirstName, tbl_patient.LastName ";
			query += "from (tbl_visit ";
			query += "inner join tbl_appointment on tbl_visit.AppointmentId = tbl_appointment.AppointmentId) ";
			query += "inner join tbl_patient on tbl_appointment.PatientId = tbl_patient.PatientId ";
			query += "where tbl_visit.VisitId = " + visitId + " and tbl_visit.IsDeleted = 0";
		}
		else if((type.equals("Patient")) || (type.equals("Staff")))
		{
			query = "select tbl_visit.AppointmentId, tbl_visit.Diagnosis, ";
			query += "tbl_visit.Prescription, tbl_visit.Dosage ";
			query += "from tbl_visit where tbl_visit.VisitId = " + visitId + " and ";
			query += "tbl_visit.IsDeleted = 0";
		}
		else
		{
			return (ResultSet)null;
		}
		rs = access.ExecuteSelect(access.connect(), query);
		return rs;
	}
	
	public String fullName()
	{
		return firstName + " " + lastName;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmailAddress() {
		return EmailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		EmailAddress = emailAddress;
	}

	public String getPhoneNum() {
		return phoneNum;
	}

	public void setPhoneNum(String phoneNum) {
		this.phoneNum = phoneNum;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSIN() {
		return SIN;
	}

	public void setSIN(String sin) {
		SIN = sin;
	}

	public String getHomeAddress() {
		return homeAddress;
	}

	public void setHomeAddress(String homeAddress) {
		this.homeAddress = homeAddress;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public java.sql.Date getDateOfBirth() {
		return DateOfBirth;
	}

	public void setDateOfBirth(java.sql.Date dateOfBirth) {
		DateOfBirth = dateOfBirth;
	}
	
	public static String monthFormat(String monthName)
	{
		if (monthName.equals("January"))
		{
			return "01";
		}
		else if (monthName.equals("February"))
		{
			return "02";
		}
		else if (monthName.equals("March"))
		{
			return "03";
		}
		else if (monthName.equals("April"))
		{
			return "04";
		}
		else if (monthName.equals("May"))
		{
			return "05";
		}
		else if (monthName.equals("June"))
		{
			return "06";
		}
		else if (monthName.equals("July"))
		{
			return "07";
		}
		else if (monthName.equals("August"))
		{
			return "08";
		}
		else if (monthName.equals("September"))
		{
			return "09";
		}
		else if (monthName.equals("October"))
		{
			return "10";
		}
		else if (monthName.equals("November"))
		{
			return "11";
		}
		else if (monthName.equals("December"))
		{
			return "12";
		}
		else
		{
			return "01"; //default is January
		}
	}
	
	public static Boolean Log(String actionBy, String sqlStr)
	{
		DbAccess access = new DbAccess();
        //java.util.Calendar calendar = java.util.Calendar.getInstance();
        java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        sqlStr = sqlStr.replace("'","");
        
        java.util.Date d = new java.util.Date();
       //dateFormat.format(d);
        
        
		String query = "insert into tbl_log (actionBy, sqlString, timeStamp) values ";
		query += "('" + actionBy + "','" + sqlStr + "','" + dateFormat.format(d) + "')";
		
		try
		{
			access.ExecuteUpdate(access.connect(), query);
		}
		catch (Exception e)
		{
			return false;
		}
		
		return true;
	}
	
}
